// pages/wantedHouse/wantedHouse.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    propertyType: [], //房产类型
    typeIndex: '', //房产类型下标
    areaData: {}, //房源区域
    areaIndex: 0, //房源区域下标

    latitude: '',//纬度
    longitude: '',//经度
    house_area: '',//房子面积  房源小区名称
    house_address: '',//小区选择


  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //获取房源属性数据
    wx.request({
      url: 'http://www.tenement.com/api/skx/house_attr',
      success: ret => {
        var propertyType = ret.data.data.property_type; //房产类型
        var areaData = ret.data.data.house_area;//区域

        // console.log(areaData);
        this.setData({
          propertyType,areaData
        })
      }
    })
  },


  //获取经纬度
  getAddress() {
    wx.chooseLocation({
      latitude: 0,
      longitude: 0,
      success: ret => {


        console.log(ret);
        this.setData({
          house_address: ret.address + ret.name,
          house_area: ret.address,
          longitude: ret.longitude,
          latitude: ret.latitude 
        })
      }
    })
  },

  //选择房产类型列表  下拉框取值  typeChange
  typeChange(e){
    var propertyType = this.data.propertyType
    var id = propertyType[e.detail.value]['id'];
    this.setData({
      typeIndex: e.detail.value,
      house_property_typeID: id
    })
  },

  //房源区域下标
  areaChange: function (e) {
    console.log(e);
    this.setData({
      areaIndex: e.detail.value
    })
  },


    //表单提交
    formSubmit(e) {
      //处理值 将房产类型的值处理成id
      e.detail.value.house_property_type = this.data.house_property_typeID
      let wanted=e.detail.value
      this.setData({
        wanted
      })
      console.log(wanted);
      wx.request({
        url: 'http://www.tenement.com/api/skx/wanted_house',
        data: {
          wanted,user_id:1,seek_type:1
        },
        method: "POST",
        success: res => {

          console.log(res);
          // this.setData({
          //   slideshow:res.data
          // })
        }
      })

    },


})